package huawei.widget;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout.LayoutParams;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import o.fo;
import o.fpp;
import o.fql.c;
import o.fql.e;
import o.gg;

public class HwSubTabViewContainer extends HorizontalScrollView {
    private int ˊ;
    private final a ˋ;
    private int ˏ;
    private ValueAnimator ॱ;

    public static class a extends LinearLayout {
        private int ʻ = -1;
        private int ʼ = -1;
        private int ʽ;
        private int ˊ;
        float ˋ;
        private int ˎ;
        int ˏ = -1;
        private ValueAnimator ˏॱ;
        private Drawable ॱ;
        private int ॱॱ = -1;
        private final Paint ᐝ;

        a(Context context) {
            super(context);
            setWillNotDraw(false);
            this.ᐝ = new Paint();
            this.ॱ = fo.ˊ(context, e.ˎ);
        }

        public void setSelectedIndicatorColor(int i) {
            if (this.ᐝ.getColor() != i) {
                if (VERSION.SDK_INT < 21) {
                    this.ॱ = gg.ʻ(this.ॱ).mutate();
                    gg.ॱ(this.ॱ, i);
                } else {
                    this.ॱ.setTint(i);
                }
                this.ᐝ.setColor(i);
                postInvalidateOnAnimation();
            }
        }

        void ˊ(int i) {
            if (this.ˎ != i) {
                this.ˎ = i;
                postInvalidateOnAnimation();
            }
        }

        void ˏ(int i) {
            if (this.ˊ != i) {
                this.ˊ = i;
                postInvalidateOnAnimation();
            }
        }

        void ॱ(int i) {
            this.ʽ = i;
        }

        boolean ॱ() {
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                if (getChildAt(i).getWidth() <= 0) {
                    return true;
                }
            }
            return false;
        }

        void ˊ(int i, float f) {
            if (this.ˏॱ != null && this.ˏॱ.isRunning()) {
                this.ˏॱ.cancel();
            }
            this.ˏ = i;
            this.ˋ = f;
            ˊ();
        }

        public void onRtlPropertiesChanged(int i) {
            super.onRtlPropertiesChanged(i);
            if (VERSION.SDK_INT < 23 && this.ॱॱ != i) {
                requestLayout();
                this.ॱॱ = i;
            }
        }

        protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
            super.onLayout(z, i, i2, i3, i4);
            if (this.ˏॱ == null || !this.ˏॱ.isRunning()) {
                ˊ();
                return;
            }
            this.ˏॱ.cancel();
            ˋ(this.ˏ, Math.round(((float) this.ˏॱ.getDuration()) * (1.0f - this.ˏॱ.getAnimatedFraction())));
        }

        private void ˊ() {
            int i;
            int i2 = -1;
            View childAt = getChildAt(this.ˏ);
            if (childAt == null || childAt.getWidth() <= 0) {
                i = -1;
            } else {
                i = childAt.getPaddingLeft() + childAt.getLeft();
                i2 = childAt.getRight() - childAt.getPaddingRight();
                if (this.ˋ > 0.0f && this.ˏ < getChildCount() - 1) {
                    childAt = getChildAt(this.ˏ + 1);
                    int left = childAt.getLeft() + childAt.getPaddingLeft();
                    i = (int) ((((float) i) * (1.0f - this.ˋ)) + (((float) left) * this.ˋ));
                    i2 = (int) ((((float) i2) * (1.0f - this.ˋ)) + (((float) (childAt.getRight() - childAt.getPaddingRight())) * this.ˋ));
                }
            }
            ˏ(i, i2);
        }

        void ˏ(int i, int i2) {
            if (i != this.ʻ || i2 != this.ʼ) {
                this.ʻ = i;
                this.ʼ = i2;
                postInvalidateOnAnimation();
            }
        }

        void ˋ(final int i, int i2) {
            View childAt;
            if (this.ˏॱ != null && this.ˏॱ.isRunning()) {
                this.ˏॱ.cancel();
                this.ˏ = i;
            }
            if (getLayoutDirection() == 1) {
                childAt = getChildAt(i);
            } else {
                childAt = getChildAt(i);
            }
            if (childAt == null) {
                ˊ();
                return;
            }
            final int left = childAt.getLeft() + childAt.getPaddingLeft();
            final int right = childAt.getRight() - childAt.getPaddingRight();
            final int i3 = this.ʻ;
            final int i4 = this.ʼ;
            if (i3 != left || i4 != right) {
                ValueAnimator valueAnimator = new ValueAnimator();
                this.ˏॱ = valueAnimator;
                valueAnimator.setInterpolator(fpp.ˋ);
                valueAnimator.setDuration((long) i2);
                valueAnimator.setFloatValues(new float[]{0.0f, 1.0f});
                valueAnimator.addUpdateListener(new AnimatorUpdateListener(this) {
                    final /* synthetic */ a ˎ;

                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        float animatedFraction = valueAnimator.getAnimatedFraction();
                        this.ˎ.ˏ(fpp.ˊ(i3, left, animatedFraction), fpp.ˊ(i4, right, animatedFraction));
                    }
                });
                valueAnimator.addListener(new AnimatorListenerAdapter(this) {
                    final /* synthetic */ a ˎ;

                    public void onAnimationEnd(Animator animator) {
                        this.ˎ.ˏ = i;
                        this.ˎ.ˋ = 0.0f;
                    }
                });
                valueAnimator.start();
            }
        }

        public void draw(Canvas canvas) {
            int totalPaddingBottom;
            super.draw(canvas);
            if (this.ˏ != -1) {
                totalPaddingBottom = ((TextView) getChildAt(this.ˏ)).getTotalPaddingBottom() - this.ˊ;
            } else {
                totalPaddingBottom = 0;
            }
            if (this.ʻ >= 0 && this.ʼ > this.ʻ) {
                this.ॱ.setBounds(0, 0, this.ʼ - this.ʻ, this.ˎ);
                canvas.save();
                canvas.translate((float) this.ʻ, (float) ((getHeight() - this.ˎ) - totalPaddingBottom));
                this.ॱ.draw(canvas);
                canvas.restore();
            }
        }
    }

    public HwSubTabViewContainer(Context context) {
        this(context, null);
    }

    public HwSubTabViewContainer(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwSubTabViewContainer(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        setHorizontalScrollBarEnabled(false);
        this.ˋ = new a(context);
        super.addView(this.ˋ, 0, new LayoutParams(-2, -1));
        this.ˊ = getResources().getDimensionPixelOffset(c.ˏ);
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        View childAt = getChildAt(0);
        if (ˏ()) {
            int i5 = this.ˊ - this.ˏ;
            childAt.setPadding(i5, 0, i5, 0);
            setHorizontalFadingEdgeEnabled(true);
            setFadingEdgeLength(this.ˊ);
            return;
        }
        i5 = -this.ˏ;
        setHorizontalFadingEdgeEnabled(false);
        childAt.setPadding(i5, 0, i5, 0);
    }

    protected float getRightFadingEdgeStrength() {
        return 1.0f;
    }

    protected float getLeftFadingEdgeStrength() {
        return 1.0f;
    }

    public a ˎ() {
        return this.ˋ;
    }

    void ˋ(int i) {
        this.ˏ = i;
        View childAt = getChildAt(0);
        if (ˏ()) {
            int i2 = this.ˊ - this.ˏ;
            childAt.setPadding(i2, 0, i2, 0);
        }
    }

    public void ˏ(int i) {
        if (i != -1) {
            if (getWindowToken() == null || this.ˋ.ॱ()) {
                setScrollPosition(i, 0.0f);
                return;
            }
            if (getScrollX() != ˋ(i, 0.0f)) {
                ˋ();
                this.ॱ.setIntValues(new int[]{r0, r1});
                this.ॱ.start();
            }
            this.ˋ.ˋ(i, 200);
        }
    }

    private void ˋ() {
        if (this.ॱ == null) {
            this.ॱ = new ValueAnimator();
            this.ॱ.setInterpolator(fpp.ˋ);
            this.ॱ.setDuration(200);
            this.ॱ.addUpdateListener(new AnimatorUpdateListener(this) {
                final /* synthetic */ HwSubTabViewContainer ॱ;

                {
                    this.ॱ = r1;
                }

                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    this.ॱ.scrollTo(((Integer) valueAnimator.getAnimatedValue()).intValue(), 0);
                }
            });
        }
    }

    public void setScrollPosition(int i, float f) {
        setScrollPosition(i, f, true);
    }

    public void setScrollPosition(int i, float f, boolean z) {
        int round = Math.round(((float) i) + f);
        if (round >= 0 && round < this.ˋ.getChildCount()) {
            if (z) {
                this.ˋ.ˊ(i, f);
            }
            if (this.ॱ != null && this.ॱ.isRunning()) {
                this.ॱ.cancel();
            }
            scrollTo(ˋ(i, f), 0);
        }
    }

    private int ˋ(int i, float f) {
        int width;
        int width2;
        int i2 = 0;
        View childAt = this.ˋ.getChildAt(i);
        View childAt2 = i + 1 < this.ˋ.getChildCount() ? this.ˋ.getChildAt(i + 1) : null;
        if (childAt != null) {
            width = childAt.getWidth();
        } else {
            width = 0;
        }
        if (childAt2 != null) {
            width2 = childAt2.getWidth();
        } else {
            width2 = 0;
        }
        if (childAt != null) {
            i2 = (childAt.getLeft() + (width / 2)) - (getWidth() / 2);
        }
        width2 = (int) (((((float) (width2 + width)) * 0.5f) + ((float) (this.ˏ * 2))) * f);
        if (getLayoutDirection() == 0) {
            return i2 + width2;
        }
        return i2 - width2;
    }

    public boolean ˏ() {
        View childAt = getChildAt(0);
        ViewParent parent = getParent();
        if (childAt == null || parent == null || !(parent instanceof ViewGroup)) {
            return false;
        }
        if (getMeasuredWidth() < (childAt.getMeasuredWidth() + getPaddingStart()) + getPaddingEnd() || getMeasuredWidth() + this.ˊ > ((ViewGroup) parent).getMeasuredWidth()) {
            return true;
        }
        return false;
    }
}
